

import java.io.IOException;

public class ExOnProcess1  {

	protected final int[] SUCCESS = {1};
	protected final int[] FAIL = {0};
	private String arguments ="";
	private int timeout = 25000;
	private int[] acceptableValue = {0};
	private int retries = 2;

	public int[] _ExecuteTask() {
		Process process = null;
		Worker worker = null;
		try {
			process = Runtime.getRuntime().exec("C:\\Program Files (x86)\\Notepad++\\notepad++.exe" + " " + arguments);
			
			System.out.println("----------------------------------------------------------------------");
			while (retries > 0) {
				System.out.println("executing process"+retries);
				worker = new Worker(process);
				worker.start();
				worker.join(timeout);

				if (worker.exit != null) {
					int i = worker.exit;
					System.out.println("Return Type : " + i);
					for (int j : acceptableValue) {
						if (i == j)
							return SUCCESS;
					}
				} else {
					worker.interrupt();
					//return FAIL;
				}
				retries --;
			}

		} catch (IOException e) {
			System.out.println("IO Exception");
			e.printStackTrace();
		} catch (InterruptedException e) {
			System.out.println("Interrupted Exceptiondfasdfasdfs");
		    e.printStackTrace();
		} catch (Exception e){
			System.out.println("Exception");
			e.printStackTrace();
		}finally {
			process.destroy();
		}
		System.out.println("process failed");
		return FAIL;
	}
	public static void main(String[] args) {
		ExOnProcess1 exp = new ExOnProcess1();
		int arr[] = exp._ExecuteTask();
		System.out.println(arr[0]+"output");
		
		
	}

	private static class Worker extends Thread {
		private final Process process;
		private Integer exit;
		private Worker(Process process) {
			this.process = process;
		}
		public void run() {
			try { 
				exit = process.waitFor();
			} catch (InterruptedException ignore) {
				System.out.println("Interrupted Exception");
				return;
			}
		}  
	}
}